<template>
	<view style="width: 100%;height: 100%;">
		<!-- 头部 -->
		<view class="theme-container" style="position: relative;">
			<view :style="{height: sConf.tH+'px'}"></view>
			<view class="top-font-title"
				style="font-size: x-large;font-weight: bolder;padding: 35px 0;color: #fff;text-align: center;">
				{{title}}
			</view>
			<tn-subsection v-model="curTabs" @change="EventAction">
				<tn-subsection-item v-for="(item,index) in tabsData" :key="index" :title="item"></tn-subsection-item>
			</tn-subsection>
		</view>
		<view class="mainContent">
			<scroll-view scroll-y @scrolltolower="lastPage" style="width: 100%;height: 80vh;padding: 5px 10px;">
				<tn-empty v-if="tmpData.length === 0" mode="data"></tn-empty>
				<template v-for="(pages, index) in tmpData" :key="index">
					<sub-point-card v-for="(item,index) in pages" :key="index" :data="item" :mode="curTabs"
						@click="EventChange"></sub-point-card>
				</template>
			</scroll-view>
		</view>
		<!-- 顶部自定义导航 -->
		<tn-navbar :placeholder="true" fixed bg-color="#FFFFFF00" text-color="#fff">{{sConf.title}} •
			{{title}}</tn-navbar>
	</view>

	<!-- 模态窗口 -->
	<tn-popup v-model="showPopup" open-direction="bottom">
		<view style="display: flex;justify-content: center;padding: 20px 10px;">
			<view class="">.........订单追踪功能未开放.........</view>
		</view>
	</tn-popup>
</template>

<script>
	import utils from '@/common/utils';
	export default {
		data() {
			return {
				count: null, // 记录数
				size: 20, // 页大小
				page: 1, // 当前页
				maxPage: 1, // 最大数	
				title: '我的资产',
				sConf: getApp().globalData,
				curTabs: 0,
				tabsData: ['钱包', '积分', '抵扣红包'],
				tmpData: [], // 主要数据
				showPopup: false,
			}
		},
		onLoad(args) {
			const state = Number(args.state || 0);
			this.curTabs = state;
			this.loadDefData(state)
		},
		onReady() {

		},
		methods: {
			EventAction(e) {
				console.log('EventAction', e);
				this.count = null; // 记录数
				this.size = 20; // 页大小
				this.page = 1; // 当前页
				this.maxPage = 1; // 最大数	
				this.tmpData = [] // 清空数据
				this.loadDefData(e);
			},
			/**
			 * 初始化
			 */
			loadDefData(e) {
				if (e === 0) {
					this.loadWalletList()
				} else if (e === 1) {
					this.loadPointsList()
				} else if (e === 2) {
					this.loadMasterList()
				} else {}
			},
			/**
			 * 下一页
			 */
			lastPage() {
				console.log('lastPage');
				if (this.page < this.maxPage) {
					this.page++
					this.loadDefData(this.curTabs)
				}
			},
			/**
			 * 加载钱包记录
			 */
			loadWalletList() {
				let host = this.sConf.host + '/weapps/wallet/';
				let token = this.sConf.token || '';
				let data = {
					sid: this.sConf.auth.id,
					page: this.page,
					size: this.size,
					ordering: '-id'
				}
				utils.authenticatorList(host, token, data).then((res) => {
					console.log('钱包明细', res);
					if (res.rescode === 200 && res.resmsg.length > 0) {
						this.tmpData[this.page - 1] = res.resmsg
						this.count = res.count
						this.size = res.size
						this.maxPage = Math.ceil(res.count / res.size)
					}
				});
			},
			/**
			 * 加载积分数据
			 */
			loadPointsList() {
				let host = this.sConf.host + '/weapps/points/';
				let token = this.sConf.token || '';
				let data = {
					sid: this.sConf.auth.id,
					page: this.page,
					size: this.size,
					ordering: '-id'
				}
				utils.authenticatorList(host, token, data).then((res) => {
					console.log('积分明细', res);
					if (res.rescode === 200 && res.resmsg.length > 0) {
						this.tmpData[this.page - 1] = res.resmsg
						this.count = res.count
						this.size = res.size
						this.maxPage = Math.ceil(res.count / res.size)
					}
				})
			},
			/**
			 * 加载额度数据
			 */
			loadMasterList() {
				let host = this.sConf.host + '/weapps/master/';
				let token = this.sConf.token || '';
				let data = {
					sid: this.sConf.auth.id,
					page: this.page,
					size: this.size,
					ordering: '-id'
				}
				utils.authenticatorList(host, token, data).then((res) => {
					console.log('额度明细', res);
					if (res.rescode === 200 && res.resmsg.length > 0) {
						this.tmpData[this.page - 1] = res.resmsg
						this.count = res.count
						this.size = res.size
						this.maxPage = Math.ceil(res.count / res.size)
					}
				})
			},
			/**
			 * 点击事件
			 */
			EventChange(e) {
				console.log('EventChange', e);
				// let host = this.sConf.host + '/weapps/listReqsn/';
				// let token = this.sConf.token || '';
				// let data = {
				// 	reqsn: e
				// }
				// utils.authenticatorOnList(host, token, data).then(res => {
				// 	console.log('加载订单', res);
				// }).catch(err => {
				// 	uni.showToast({
				// 		icon: 'error',
				// 		title: '加载订单失败'
				// 	})
				// })
				this.showPopup = !this.showPopup
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>